package www.dianbaozu.com.ui.chat.friend.holder

import android.view.View
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import com.bumptech.glide.Glide
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder
import com.netease.nim.uikit.databinding.ItemFriendsBinding
import www.wen.com.common.lib.data.entities.FriendEntity
import www.wen.com.common.lib.extension.glide.setImageUrl
import www.wen.com.common.lib.extension.unread

class FriendTopViewHolder(baseQuickAdapter: BaseQuickAdapter<FriendEntity, BaseViewHolder>) :
    RecyclerViewHolder<BaseQuickAdapter<FriendEntity, BaseViewHolder>, BaseViewHolder, FriendEntity>(
        baseQuickAdapter
    ) {
    private var binding: ItemFriendsBinding? = null

    override fun convert(
        holder: BaseViewHolder,
        data: FriendEntity,
        position: Int,
        isScrolling: Boolean
    ) {
        data.topEntity?.let {
            binding = DataBindingUtil.bind(holder.itemView)
            binding?.apply {
                tvSubtitle.visibility = View.VISIBLE
                imgArrow.visibility = View.VISIBLE
                tvTopStatus.visibility = View.GONE
                imgOnlineStatus.visibility = View.GONE
//                setImageUrl(ivAvatar,it.icon)
                Glide.with(holder.context).load(it.icon).into(ivAvatar)

                tvTitle.text = it.title
                tvSubtitle.text = it.subTitle
                tvUnreadMessage.text = it.unreadCount.unread()
                slUnreadMessage.isVisible = it.unreadCount > 0
            }
        }
    }
}